import static org.junit.Assert.*;

import org.junit.Test;

/**
 * This JUnit test is a test of the Store.removeItems(int[]) method used in Store transactions.
 * 
 * @author Taylor Holden
 *
 */
public class StoreTest {

	private Store s = new Store(0); //The first store in the game. All items in the inventory are set to 2000.
	private int[] quants = new int[7]; //Array of item quantities to remove
	
	/**
	 * This function tests removing zero items from the Store inventory.
	 */
	@Test
	public void testRemovingNoItems() 
	{
		s = new Store(0);
		int[] currQuantities = new int[7];
		quants = new int[7];
		
		for(int i = 0; i < currQuantities.length; i++)
			currQuantities[i] = s.getQuantities()[i];
		
		//System.out.println(s.removeItems(quants));
		assertTrue(s.removeItems(quants));
		
		for(int i = 0; i < currQuantities.length; i++)
		{
		//	System.out.println(currQuantities[i] + " == " + s.getQuantities()[i]);
			assertTrue(currQuantities[i] == s.getQuantities()[i]);
		}
	}
	
	/**
	 * This function tests removing all items from the Store inventory.
	 */
	@Test
	public void testRemovingAllItems()
	{
		s = new Store(0);
		int[] targetQuantities = new int[7]; //Array of zeroes, as we want no remaining items in the Store.
		
		for(int i = 0; i < quants.length; i++)
			quants[i] = s.getQuantities()[i];
		
		assertTrue(s.removeItems(quants));
		
		for(int i = 0; i < targetQuantities.length; i++)
		{
			//System.out.println(targetQuantities[i] == s.getQuantities()[i]);
			assertTrue(targetQuantities[i] == s.getQuantities()[i]);
		}
	}
	
	@Test
	public void testRemovingSomeItems()
	{
		s = new Store(0);
		int[] targetQuantities = new int[7];
		quants = new int[7];
		
		for(int i = 0; i < quants.length; i++)
		{
			quants[i] = (int) (Math.random()*s.getQuantities()[i]); //quants[i] = random value between 0 and # of items in store
			targetQuantities[i] = s.getQuantities()[i] - quants[i];
		}
		
		assertTrue(s.removeItems(quants));
		
		for(int i = 0; i < targetQuantities.length; i++)
			assertTrue(targetQuantities[i] == s.getQuantities()[i]);
	}
	
	@Test
	public void testRemovingNegativeItems()
	{
		s = new Store(0);
		int[] targetQuantities = new int[7];
		quants = new int[7];
		
		for(int i = 0; i < quants.length; i++)
		{	
			quants[i] = -(int) (Math.random()*s.getQuantities()[i]); //quants[i] = random negative number between -1*# of items in store and 0
			targetQuantities[i] = s.getQuantities()[i];
		}
		
		assertFalse(s.removeItems(quants));
		
		for(int i = 0; i < targetQuantities.length; i++)
			assertTrue(targetQuantities[i] == s.getQuantities()[i]);
	}
	
	@Test
	public void testRemovingTooManyItems()
	{
		s = new Store(0);
		int[] targetQuantities = new int[7];
		quants = new int[7];
		
		for(int i = 0; i < quants.length; i++)
		{	
			quants[i] = (int) (Math.random()*s.getQuantities()[i]); //quants[i] = random negative number between -1*# of items in store and 0
			targetQuantities[i] = s.getQuantities()[i];
		}
		
		quants[5] = Integer.MAX_VALUE;
		
		assertFalse(s.removeItems(quants));
		
		for(int i = 0; i < targetQuantities.length; i++)
			assertTrue(targetQuantities[i] == s.getQuantities()[i]);	
	}
	
	@Test
	public void testRemovingNull()
	{
		int[] targetQuantities = new int[7];
		
		for(int i = 0; i < quants.length; i++)
			targetQuantities[i] = s.getQuantities()[i];
		
		quants = null;
		
		assertFalse(s.removeItems(quants));
		
		for(int i = 0; i < targetQuantities.length; i++)
			assertTrue(targetQuantities[i] == s.getQuantities()[i]);
	}
}
